﻿using System.Collections.Generic;
using System.Reflection;

namespace ZeBobo5.LibraryHelper.Core
{
    public class ListHelper
    {
        public static T FindFirst<T>(List<T> data, params string[] fieldsCondition) where T : class
        {
            return data.Find(
                delegate(T dta)
                    {
                        foreach (string item in fieldsCondition)
                        {
                            string s1 = item.Split('=')[0];
                            string s2 = item.Replace("'", "").Split('=')[1];

                            foreach (PropertyInfo p in typeof (T).GetProperties())
                            {
                                if (p.Name == s1)
                                {
                                    if (p.GetValue(dta, null).ToString() != s2)
                                    {
                                        return false;
                                    }
                                }
                            }
                        }
                        return true;
                    });
        }
    }
}